package fr.umlv.m2.jee.spij.service.attribution;

import fr.umlv.m2.jee.spij.persistence.actor.TeacherUnit;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * Display an attribution. DTO pattern. Attribut a unit to teacher
 * 
 * @author lounes
 * 
 */
@Component("attributionBean")
public class DisplayAttribution implements Serializable {
	/**
	 * Attribution id
	 */
	private long id;
	/**
	 * Attribution teacher login
	 */
	private String teacherLogin;
	/**
	 * Attribution unit name
	 */
	private String unitName;

	/**
	 * Empty constructor
	 */
	public DisplayAttribution() {

	}

	/**
	 * Constructs a DTO attribution, from teacher name and unit name.
	 * 
	 * @param teacherUnit
	 * @param unitName
	 */
	public DisplayAttribution(TeacherUnit teacherUnit, String unitName) {
		storeData(teacherUnit, unitName);

	}

	/**
	 * @param teacherLogin
	 *            the teacherLogin to set
	 */
	public void setTeacherLogin(String teacherLogin) {
		this.teacherLogin = teacherLogin;
	}

	/**
	 * @return the teacherLogin
	 */
	public String getTeacherLogin() {
		return teacherLogin;
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the unitName
	 */
	public String getUnitName() {
		return unitName;
	}

	/**
	 * @param unitName
	 *            the unitName to set
	 */
	public void setUnitName(String unitName) {
		this.unitName = unitName;
	}

	/**
	 * Stores datas from attribution into DisplayAttribution.
	 * 
	 * @param teacherUnit
	 *            the teacher unit
	 * @param unitName
	 *            the unit name
	 */
	private void storeData(TeacherUnit teacherUnit, String unitName) {
		if (teacherUnit.getId() != 0L) {
			setId(teacherUnit.getId());
		}
		if (teacherUnit.getTeacherLogin() != null) {
			setTeacherLogin(teacherUnit.getTeacherLogin());
		}
		if (unitName != null) {
			setUnitName(unitName);
		}
	}
}
